//
//  UIBarButton+Extension.swift
//  传智微博
//
//  Created by 郑亚伟 on 16/11/5.
//  Copyright © 2016年 郑亚伟. All rights reserved.
//

import Foundation
import UIKit
extension UIBarButtonItem{
    /*************************************************/
    //光标点击到如下方法，然后鼠标右击Find Call Hirarchy便可查询该方法在哪些位置被调用。专业术语：调用层级
    
    //主要用于简化控件创建
    //便利构造函数   设置一个默认值，字体为16
    //isBackButton是否是返回按钮，如果是就加返回箭头
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject, action: Selector, isBackButton: Bool = false) {
        let btn = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn?.addTarget(target, action: action, for: .touchUpInside)
        
        if isBackButton {
            let imageName = "navigationbar_back_withtext"
            btn?.setImage(UIImage(named: imageName), for: UIControlState(rawValue: 0))
            btn?.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
            btn?.sizeToFit()
        }
        
        //实例化UIBarButtonItem
        self.init(customView: btn!)
    }
}
